package leetcode;

import java.util.HashSet;

/**
 * 描述:
 *
 * @Package: codeDay01
 * @ClassName: ContainsNearbyDuplicate
 * @Author: 陈威
 * @CreateTime: 2022/1/19 15:25
 * @Description:
 */
//重复数字
public class ContainsNearbyDuplicate {

    public boolean containsNearbyDuplicate(int[] nums, int k) {
        HashSet<Integer> set = new HashSet<>();
        for(int i = 0; i < nums.length; i++) {
            if(!set.add(nums[i])) {
                return true;
            }

            if(set.size() > k) {
                set.remove(nums[i - k]);
            }
        }
        return false;
    }

    public static void main(String[] args) {
        ContainsNearbyDuplicate containsNearbyDuplicate = new ContainsNearbyDuplicate();
        containsNearbyDuplicate.containsNearbyDuplicate(null,0);
    }
}
